import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_example/get_connect/page/my_get_connect_page.dart';
import 'package:getx_example/get_connect_dio/page/my_get_connect_dio_page.dart';
import 'package:getx_example/get_connect_statemixin/page/my_get_connect_statemixin_page.dart';
import 'package:getx_example/get_getbuilder/page/my_get_page.dart';
import 'package:getx_example/get_getx/page/my_get_page.dart';
import 'package:getx_example/get_lazy_put/page/my_lzay_put_page.dart';
import 'package:getx_example/get_obx/my_obx_page.dart';
import 'package:getx_example/get_put/page/my_put_page.dart';
import 'package:getx_example/get_valuebuilder/my_get_valuebuilder_page.dart';
import 'package:getx_example/lang/my_lang_page.dart';
import 'package:getx_example/page/my_mine_page.dart';
import 'package:getx_example/get_put_find/page/my_product_detail_page.dart';
import 'package:getx_example/get_put_find/page/my_product_page.dart';
import 'package:getx_example/page/my_setting_page.dart';
import 'package:getx_example/theme/my_theme_page.dart';

class MyHomePage extends StatelessWidget {
  static const String route = "/MyHomePage";

  const MyHomePage({super.key});

  showSnackbar(Map? result) {
    if (result != null) {
      Get.snackbar("返回值", "success -> ${result["success"]}");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("路由跳转"),
          backgroundColor: context.theme.primaryColor,
        ),
        body: SingleChildScrollView(
            child: Column(children: [
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航-命名路由 跳转"),
              subtitle: const Text('Get.toNamed("/MyHomePage/MyProductPage")'),
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () {
                Get.toNamed("/MyHomePage/MyProductPage");
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航-命名路由 跳转"),
              subtitle: const Text('Get.toNamed("/MyHomePage/MyProductPage/MySettingPage")'),
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () {
                Get.toNamed("/MyHomePage/MyProductPage/MySettingPage");
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- 类对象"),
              subtitle: const Text('Get.to(const MySettingPage());'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () {
                Get.to(const MySettingPage());
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航 - 清除上一个, 先到 MyProductPage, 在使用 Get.off 验证 清除上一个, 在使用 Get.offAll 验证 清除所有 "),
              subtitle: const Text('Get.to(const MyProductPage());)'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () {
                Get.to(const MyProductPage());
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航-arguments传值+返回值 "),
              subtitle: const Text('Get.toNamed("/MyHomePage/MyProductPage/MySettingPage'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                var result = await Get.toNamed("/MyHomePage/MyProductPage/MySettingPage", arguments: {"id": 999});
                showSnackbar(result);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航-parameters传值+返回值 "),
              subtitle: const Text('Get.toNamed("/MyHomePage/MyProductPage/MySettingPage?id==345"))'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                var result = await Get.toNamed("/MyHomePage/MyProductPage/MySettingPage?id==345");
                showSnackbar(result);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航-parameters传值+返回值 "),
              subtitle: const Text('Get.toNamed("/MyHomePage/MyProductPage/MySettingPage/8910)'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                var result = await Get.toNamed("/MyHomePage/MyProductPage/MySettingPage/8910");
                showSnackbar(result);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航-404页面"),
              subtitle: const Text('Get.toNamed("123")'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed("123");
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- 跳转到我的页面, 检测有没有登录"),
              subtitle: const Text('Get.toNamed(MyMinePage.route);'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyMinePage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- Transition.downToUp 跳转到页面半黑屏的验证, 目前验证跟 initialRoute: 有关, 其他转场动画也会有问题"),
              subtitle: const Text('Get.toNamed(MyMinePage.route);'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MySettingPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_put, 数据刷新的验证, 覆盖了基本数据类型的刷新, 以及list, map里面的model 还有单独的model的刷新"),
              subtitle: const Text('Get.toNamed(MyCountPage.route);  适合单独的页面使用'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyPutPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_obx, 数据刷新的验证, 覆盖了基本数据类型的刷新, 以及list, map里面的model 还有单独的model的刷新"),
              subtitle: const Text('Get.toNamed(MyObxPage.route);  适合单独的页面使用'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyObxPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_getx, 数据刷新的验证, 覆盖了基本数据类型的刷新, 以及list, map里面的model 还有单独的model的刷新"),
              subtitle: const Text('Get.toNamed(MyGetxPage.route);  适合单独的页面使用'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyGetxPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_Builder, 数据刷新的验证, 覆盖了基本数据类型的刷新, 以及list, map里面的model 还有单独的model的刷新"),
              subtitle: const Text(
                  'Get.toNamed(MyGetBuilderPage.route);  这里要注意的是, 不会自动刷新,需要调用update的方法, 才会去刷新, 也可以调用 update(["id1","id2"]),进行局部刷新'),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyGetBuilderPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_valueBuilder,"),
              subtitle: const Text('Get.toNamed(MyGetValuebuilderPage.route); '),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyGetValuebuilderPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_put-find-getView, controller, 验证controller的持有传值"),
              subtitle: const Text('Get.to(const MyProductPage()); '),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.to(const MyProductPage());
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_lazy_put,"),
              subtitle: const Text('Get.toNamed(MyLazyPutPage.route); '),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyLazyPutPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- get_content, 结合网络请求"),
              subtitle: const Text('Get.toNamed(MyGetContentPage.route); '),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyGetContentPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- getConnectStateMixinPage, 结合网络请求"),
              subtitle: const Text('Get.toNamed(MyGetConnectStateMixinPage.route); '),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyGetConnectStateMixinPage.route);
              },
            ),
          ),

          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("导航- MyGetConnectDioPage, 结合网络请求"),
              subtitle: const Text('Get.toNamed(MyGetConnectDioPage.route); '),
              
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () async {
                Get.toNamed(MyGetConnectDioPage.route);
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("组件-snackbar"),
              subtitle: const Text('Get.snackbar("标题","消息",...)'),
              onTap: () =>  Get.snackbar("提示", "我是SnackBar", icon: const Icon(Icons.add))
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
                title: const Text("组件-dialog"),
                subtitle: const Text('Get.defaultDialog(...)'),
                onTap: () {
                  Get.defaultDialog(
                      title: "提示信息",
                      middleText: "你确定要删除该信息吗?",
                      textConfirm: "确认",
                      textCancel: "取消",
                      onConfirm: () {
                        debugPrint("点击了确认");
                        Get.back();
                      },
                      onCancel: () {
                        debugPrint("点击了取消");
                        Get.back();
                      });
                }),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
                title: const Text("组件-bottomSheet"),
                subtitle: const Text('Get.bottomSheet(...)'),
                onTap: () {
                  TextStyle titleStyle = TextStyle(color: Get.isDarkMode ? Colors.white : Colors.black87, fontSize: 20);

                  TextStyle subTitleStyle =
                      TextStyle(color: Get.isDarkMode ? Colors.white : Colors.black87, fontSize: 20);

                  Get.bottomSheet(Container(
                    color: Get.isDarkMode ? Colors.black87 : Colors.white,
                    height: 200,
                    child: Column(
                      children: [
                        ListTile(
                            leading: const Icon(Icons.ac_unit),
                            title: Text(
                              "选择一",
                              style: titleStyle,
                            ),
                            subtitle: Text(
                              "描述一",
                              style: subTitleStyle,
                            )),
                        ListTile(
                            leading: const Icon(Icons.ac_unit),
                            title: Text(
                              "选择二",
                              style: titleStyle,
                            ),
                            subtitle: Text(
                              "描述二",
                              style: subTitleStyle,
                            )),
                      ],
                    ),
                  ));
                }),
          ),

          // 多语言
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("修改语言"),
              subtitle: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "title -> ${'title'.tr}",
                    style: const TextStyle(fontSize: 24),
                  ),
                  Text(
                    "login -> ${'login'.trParams({'name': 'ducafecat', 'email': 'ducafecat@gmail.com'})}",
                    style: const TextStyle(fontSize: 24),
                  ),
                ],
              ),
              onTap: () => Get.toNamed(MyLangPage.route),
            ),
          ),

          // 主题
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("Theme"),
              trailing: const Icon(Icons.arrow_forward_ios),
              subtitle: const Text('Get.toNamed(MyThemePage.route)'),
              onTap: () => Get.toNamed(MyThemePage.route),
            ),
          ),
        ])));
  }
}
